var companySubMenu = null;
var SLIDE_TIME = 0;
var company = null;
var button = null;

$(function(){
    company = $(".top_menu_list li.right");
    companySubMenu = $("#sub_menu_company");
    button = company.children(0);
    
    setSubMenuPosition();
    $(window).resize(setSubMenuPosition);
    
    company.hover( showSubMenu,  hideSubMenu );
    
    companySubMenu.children().each(function(){

        $(this).mouseover(function(event){
            $(this).css({'background-color': '#84a5b3'});            
        });
        $(this).mouseout(function(event){
            $(this).css({'background-color': '#FFF'});
        });        
    });
});

function setSubMenuPosition()
{
    var pos = company.offset();
    
    var isIE6 =  ( jQuery.browser.version.substring(0, 2) == "6." ) ;
    if(!isIE6)
    {
        companySubMenu.css('top', pos.top + 32)
                      .css('left', pos.left);
    }
}

function showSubMenu()
{
    companySubMenu.show(SLIDE_TIME);

    if(needChangeButtonStyle())
    {
        setCompanyMenuActive();
    }
}

function hideSubMenu()
{
    companySubMenu.hide(SLIDE_TIME);
    if(needChangeButtonStyle())
    {
        setCompanyMenuInactive();
    }
}

function needChangeButtonStyle()
{
    var style = button.attr('class');
    return style != 'company menu_item_selected';
}

function setCompanyMenuActive()
{
    button.css('background', 'url(/images/top_menu_sprite.gif) repeat-x left -218px')

    var buttonText = button.children(0);
    buttonText.css('color', '#de321e');

    var rightSide = buttonText.next();
    rightSide.css('background-position', '0 -148px');
}

function setCompanyMenuInactive()
{
    button.css('background', 'none no-repeat scroll 0 0 #E6EEF1');

    var buttonText = button.children(0);
    buttonText.css('color', '#2F363A');

    var rightSide = buttonText.next();
    rightSide.css('background-position', '0 -113px');
}